#include <stdio.h> 
#include <stdlib.h> 
#include<string.h> 
#include<math.h> 
int main()
{
	int n, m, i, j, str[1000];
	int number, k = 0;
	scanf("%d%d", &n, &m);
	number = n;
	for (j = 1; j <= n; j++)
		str[j - 1] = j;
	while (number > 1)
	{
		for (i = 0; i < n; i++)
		{
			if (str[i] == 0)
				continue;
			else
				k++;
			if (k == m)
			{
				str[i] = 0;
				k = 0;
				number--;
				if (number == 1)
					break;
			}
		}
	}
	for (i = 0; i < n; i++)
	{
		if (str[i] != 0)
			printf("%d", str[i]);
	}
	return 0;
}